package com.combetter.changxing.http.cookies;

import android.util.Log;


import java.io.IOException;
import java.util.HashSet;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Author: qintao
 * E-mail: 954280376@qq.com
 * Date: 2018/3/23 10:20
 * Description: AddCookiesInterceptor 发送网络请求之前添加Cookies的拦截器
 */

public class AddCookiesInterceptor implements Interceptor {
    private static final String TAG = "SmartHttp";
    @Override
    public Response intercept(Chain chain) throws IOException {
        Log.d(TAG,"AddCookiesInterceptor start");
        Request.Builder builder = chain.request().newBuilder();

        //正常接收cookie方式
//        HashSet<String> cookies = (HashSet<String>) SPUtils.getInstance().getStringSet("cookies", new HashSet<>());
//        for (String cookie : cookies) {
//            builder.addHeader("Cookie", cookie);
//        }

        //能联网接收cookie方式
//        builder.addHeader("Cookie", SPUtils.getInstance().getString("cookies"));

        Response response = chain.proceed(builder.build());
        Log.d(TAG,"AddCookiesInterceptor end");
        return response;
    }
}
